<!DOCTYPE html>
<html>
<!--
author:guojunyu
date:2019-05
desc:this demo is about blog. PLEASE NOTE:If you have trouble running it ,try any of the other demos or connect with auther.
A ny individuals and organizations and not for commercial use, professiona website for customized web site.
-->
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="/static/css/login_reglogin.css"/>
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
        <title>登陆</title>
</head>
<body>
	<div class="bg">
		<img src="/static/images/b.jpg" alt="">
	</div>
	<div class="main">
		<div class="header" >
			<h1>Login!</h1>
		</div>
		<p></p>
			<ul class="right-form">
				<h2>Login:</h2>
				<li><input type="text" class="username" name="username" placeholder="Username" required/></li>
				<li><input type="password" class="password" name="password" placeholder="Password" required/></li>
				<li><span>微博登录</span></li>
				<input type="button" value="登录" onclick='login()'>
				<div class="clear"> </div>
			</ul>
			<div class="clear"> </div>
	</div>
	
</body>
<script>
     function login(){
        var username=$('.username').val();
		var password=$('.password').val();
		var post_data={'username':username,'password':password};
		console.log(post_data);
        

		$.ajax({
			url:'http://127.0.0.1:8000/v1/tokens',
			type:'post',
		   //发送的数据
			data:JSON.stringify(post_data),
			//发送格式
			contentType:'appliction/json',
			//期望返回的数据格式
			dataType:'json',
			success:function(res){
				if (res.code=200){
					//token username本地存储
					window.localStorage.setItem('dnblog_token',res.data.token);
					window.localStorage.setItem("dnblog_user",res.username);
					alert('登录成功');
					//登录成功后重定向 自己的文章列表
					window.location='/'+res.username +'/topics';
				}else{
					alert(res.error)
				}
			}


		})

	 }


</script>

</html>
